package com.example.map.myapplication.fragmentdemo1;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import org.greenrobot.eventbus.EventBus;
/**
 * Created by qundui on 2017/5/26.
 */

public class A extends ListFragment {
    private Demo demo;
    private Handler mhandle;
    private B b;
    final String[]  mdatas={"第一页","第二页","第三页"};
//    final String[] rightData={"第一页内容","第二页内容","第三页内容"};
//    interface MycallBack {
//     void SwichPos(int pos);
//}
//MycallBack mcallback;
    //注意衣服是才可以吧处理逻辑交给宿主handle,并拿到handle
    @Override
    public void onAttach(Activity activity) {
//        demo= (Demo) activity;
//       mhandle= demo.getHandle();
//        if (activity instanceof MycallBack){
//           mcallback= (MycallBack) activity;// 对象上转性,类似C++风格多继承,其实是Java里面实现类 control+T 查看一下viewtree 便知
//        }
        super.onAttach(activity);

    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        return super.onCreateView(inflater, container, savedInstanceState);
    }
// 此时可以拿到别的Fragment
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
       // b= (B) demo.getSupportFragmentManager().findFragmentById(R.id.b);
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
    }
    //  注意此时 listview 才创建
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {

        setListAdapter(new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,android.R.id.text1,mdatas));
        getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                b.getTv().setText(rightData[position]);
//                Message m=Message.obtain();
//                m.what=position;
//                mhandle.sendMessage(m);
                EventBus.getDefault().post(new MeassageEvent(position));
//               new Bus().post(new MeassageEvent(position));
//                mcallback.SwichPos(position);
            }
        });

        super.onViewCreated(view, savedInstanceState);
    }
}
